import shortuuid
from sqlalchemy import Column, Integer, func, ForeignKey, String, DateTime
from sqlalchemy.orm import relationship

from database import db
from .account import Account
from .resource import Resource


class Member(db.Model):
    __tablename__ = 'member'
    id = Column(String(80), primary_key=True)
    screen_name = Column(String(200))
    first_name = Column(String(200), nullable=True)
    last_name = Column(String(200), nullable=True)
    grade = Column(String(10), default='male')
    phone = Column(String(30), nullable=True)
    email = Column(String(200), nullable=True)
    status = Column(String(20), default='normal')
    created_at = Column(DateTime(), default=func.now())
    updated_at = Column(DateTime(), default=func.now())
    deal_count = Column(Integer(), default=0)
    level = Column(Integer(), default=0)
    secret_key = Column(String(80), default=shortuuid.uuid)
    country = Column(String(80), nullable=True)
    head_image_id = Column(ForeignKey(Resource.id))
    seller_score = Column(Integer,default=0,doc='卖家评价')
    buyer_score = Column(Integer,default=0,doc='买家评价')
    head_image = relationship(Resource)
    account_id = Column(ForeignKey(Account.id))
    account = relationship(Account)
